package epoverty;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import net.miginfocom.swing.MigLayout;

public class Donations extends JPanel
{
   private final int width = super.getWidth();
   private final int heigth = super.getHeight();
   private final int font = 20;
   private JTextField firstName_TF;
   private JTextField lastName_TF;
   private Connection conn;
   private myTable pTable = new myTable();
   private int pColCount = 2;
   private String[] pColNames = new String[pColCount];
   private JTable pJTable = new JTable(pTable);
   private JScrollPane pScrollPane = new JScrollPane(pJTable);
   private PreparedStatement pstmt;
   private ResultSet prs;
   private ResultSetMetaData pmd;
   private BackgroundPanel topLabel;
   private BackgroundPanel topDonationsTab;
   private BackgroundPanel bottomDonationsTab;
   private BackgroundPanel middleDonationsTab;
   private JLabel donorName;
   private JLabel phone;
   private JLabel email;
   private JLabel totalDonation;
   private JLabel lastDonationDate;
   private JLabel lastDonationAmount;
   private JPanel mainPanel;
   private Border border;
   private Border insideBorders;
   private Border bottom;
   private Border topLeftBottom;
   private Border topRightBottom;
   private Border topLeft;
   private Border left;
   private Border leftBottom;
   private Border topRight;
   private Border right;
   private Border bottomRight;
   GridBagConstraints gBC = new GridBagConstraints();

   Donations(JTabbedPane tabs) throws SQLException, ClassNotFoundException
   {
      Border compoundProgress;
      Border raisedbevel = BorderFactory.createRaisedBevelBorder();
      Border loweredbevel = BorderFactory.createLoweredBevelBorder();
      border = BorderFactory.createLineBorder(Color.GREEN);
      compoundProgress = BorderFactory.createCompoundBorder(raisedbevel, loweredbevel);
      insideBorders = BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.GREEN), compoundProgress);
      compoundProgress = BorderFactory.createCompoundBorder(border, compoundProgress);
      
      topLeftBottom = BorderFactory.createMatteBorder(4, 4, 4, 0, EPovertyMain.darkest);
      topRightBottom = BorderFactory.createMatteBorder(4, 0, 4, 4, EPovertyMain.darkest);
      topLeft = BorderFactory.createMatteBorder(4, 4, 0, 0, EPovertyMain.darkest);
      left = BorderFactory.createMatteBorder(0, 4, 0, 0, EPovertyMain.darkest);
      leftBottom = BorderFactory.createMatteBorder(0, 4, 4, 0, EPovertyMain.darkest);
      right = BorderFactory.createMatteBorder(0, 0, 0, 4, EPovertyMain.darkest);
      bottomRight = BorderFactory.createMatteBorder(0, 0, 4, 4, EPovertyMain.darkest);
      topRight = BorderFactory.createMatteBorder(4, 0, 0, 4, EPovertyMain.darkest);
      bottom = BorderFactory.createMatteBorder(0, 0, 4, 0, EPovertyMain.darkest);
      
      
      setupMainPanel();
      createRecentDonationsContent();
      createIndividualDonorContent();
      createSearchContent();
      addRecentDonationsData();
      addIndividualDoorData();
      addSearchData();
       
          
      pJTable.getSelectionModel().addListSelectionListener(
              new ListSelectionListener(){

            @Override
            public void valueChanged(ListSelectionEvent e) {
                try {
                    if(pJTable.getSelectedRow() < 0)
                        return;
                    if (e.getValueIsAdjusting()) {
                        return;
                    }
                    ListSelectionModel model = pJTable.getSelectionModel();   
                    int lead = model.getLeadSelectionIndex();   
                    
                    String fName = pJTable.getValueAt(lead, 0).toString();
                    String lName = pJTable.getValueAt(lead, 1).toString();
                    String query = "SELECT firstName, lastName, phoneNumber, emailAddress "
                         + "FROM persons "
                         + "WHERE firstName = '" + fName + "' "
                         + "AND lastName = '" + lName + "'";
                    
                    conn = DBconnection.getConnection();
                    PreparedStatement pstmt1 = (PreparedStatement) conn.prepareStatement(query);
                    
                    ResultSet personResultSet = (ResultSet) pstmt1.executeQuery();
                    ResultSetMetaData personMetaData = (ResultSetMetaData) personResultSet.getMetaData();
                    Object[] data = new String[personMetaData.getColumnCount()];
                      
                    while (personResultSet.next())
                    {
                        for (int i = 1; i <= data.length; i++)
                        {
                            data[i - 1] = personResultSet.getString(i);
                        }
                      }
                      
                      donorName.setText(fName + " " + lName);
                      phone.setText(data[2].toString());
                      email.setText(data[3].toString());                      
                      
                      query = "Select SUM(donationAmount) "
                        + "From donations d "
                        + "INNER JOIN donors o on d.donorId = o.donorId "
                        + "INNER JOIN persons p on p.personId = o.personId "
                        + "WHERE firstName = '"+ fName + "' "
                        + "AND lastName = '"+ lName + "'";
                      
                     
                    PreparedStatement pstmt2 = (PreparedStatement) conn.prepareStatement(query);
                    
                    ResultSet totalDonationsRS = (ResultSet) pstmt2.executeQuery();
                    String sum = null;
                    while (totalDonationsRS.next())
                    {
                        sum = totalDonationsRS.getString(1);  
                    }
                    
                    totalDonation.setText("$" + sum);
                    
                    query = "SELECT DISTINCT DATE_FORMAT(donationDate, '%b %D, %Y'), donationAmount "
                        + "FROM donations d "
                        + "INNER JOIN donors o ON d.donorId = o.donorId "
                        + "INNER JOIN persons p on p.personId = o.personId "
                        + "WHERE p.firstName = '" + fName + "' "
                        + "AND p.lastName = '"+ lName +"' "
                        + "AND donationDate = (SELECT MAX(donationDate) "
                            + "FROM donations d "
                            + "INNER JOIN donors o on d.donorId = o.donorId "
                            + "INNER JOIN persons p on p.personId = o.personId "
                            + "WHERE p.firstName = '" + fName +"' "
                            + "AND p.lastName = '" + lName + "')";
                    
                    PreparedStatement pstmt3 = (PreparedStatement) conn.prepareStatement(query);
                    
                    ResultSet lastDonationRS = (ResultSet) pstmt3.executeQuery();
                    ResultSetMetaData lastDonationMD = (ResultSetMetaData) lastDonationRS.getMetaData();
                    Object[] lastDonation = new String[lastDonationMD.getColumnCount()];
                    
                    while (lastDonationRS.next())
                    {
                        for (int i = 1; i <= lastDonation.length; i++)
                        {
                            lastDonation[i - 1] = lastDonationRS.getString(i);
                        }
                    }
                    
                    lastDonationDate.setText("Date: " + lastDonation[0]);
                    lastDonationAmount.setText("Amount: $" + lastDonation[1]);
                    
                      
                    //middleDonationsTab.updateUI();
                      mainPanel.repaint();
                      conn.close();
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(Donations.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SQLException ex) {
                    Logger.getLogger(Donations.class.getName()).log(Level.SEVERE, null, ex);
                }
                
            }
              
              });
      
      // ADD TOP AND BOTTOM TO THE MAIN AND PUT THEM INTO A TAB
      mainPanel.add(topLabel, "growx");
      mainPanel.add(topDonationsTab, "grow");
      mainPanel.add(middleDonationsTab, "growx");
      mainPanel.add(bottomDonationsTab, "grow");
      
      tabs.add("", mainPanel);
      DBconnection.closeConnection();
   }

    private void setupMainPanel() {
        
        mainPanel = new JPanel();
        mainPanel.setLayout(new MigLayout("wrap 1, fill, insets 0"));
        mainPanel.setBorder(border);
        mainPanel.setBackground(Color.DARK_GRAY);
    }

    private void createRecentDonationsContent() {
        topLabel = new BackgroundPanel(null, BackgroundPanel.ACTUAL, 1.0f, 0.5f);      
        topLabel.setBorder(insideBorders);      
        topLabel.setLayout(new GridLayout(1, 1, 1, 1));      
        Dimension topLabeld = new Dimension(width, 50);      
        topLabel.setPreferredSize(topLabeld);      
      
        topDonationsTab = new BackgroundPanel(null, BackgroundPanel.ACTUAL, 1.0f, 0.5f);      
        topDonationsTab.setBorder(insideBorders);      
        topDonationsTab.setLayout(new GridLayout(0, 1, 1, 1));      
        Dimension topDonation = new Dimension(width, 320);      
        topDonationsTab.setPreferredSize(topDonation);      
        GradientPaint paintTopDonations = new GradientPaint(0, 0, Color.BLACK, 100, 100, Color.DARK_GRAY);
        topDonationsTab.setPaint(paintTopDonations);
    }

    private void createIndividualDonorContent() {
        middleDonationsTab = new BackgroundPanel(null, BackgroundPanel.ACTUAL, 1.0f, 0.5f);      
        middleDonationsTab.setBorder(insideBorders);      
        middleDonationsTab.setLayout(new GridBagLayout());      
        Dimension middleDonations = new Dimension(width, 150);      
        middleDonationsTab.setPreferredSize(middleDonations);      
        GradientPaint paintMidDonations = new GradientPaint(0, 0, Color.BLACK, 100, 100, Color.DARK_GRAY);      
        middleDonationsTab.setPaint(paintMidDonations);
    }

    private void createSearchContent() { 
        bottomDonationsTab = new BackgroundPanel(null, BackgroundPanel.ACTUAL, 1.0f, 0.5f);      
        bottomDonationsTab.setBorder(insideBorders);      
        bottomDonationsTab.setLayout(new GridBagLayout());      
        Dimension bottomDonations = new Dimension(width, 200);      
        bottomDonationsTab.setPreferredSize(bottomDonations);      
        GradientPaint paintBottomFundraiser = new GradientPaint(0, 150, Color.LIGHT_GRAY, 100, 50, Color.DARK_GRAY);      
        bottomDonationsTab.setPaint(paintBottomFundraiser);
    }

    private void addRecentDonationsData() throws SQLException, ClassNotFoundException {
        //setup ui for jtable
        UIManager.put("Table.background", Color.DARK_GRAY);
        UIManager.put("Table.foreground", Color.WHITE);
        UIManager.put("Table.font", new Font("SansSerif", Font.BOLD, 14));
        UIManager.put("Table.selectionBackground", Color.GREEN);
        UIManager.put("Table.selectionForeground", Color.BLACK);
        UIManager.put("Table.gridColor", Color.BLACK);
        UIManager.put("TableHeader.background", Color.GRAY);
        UIManager.put("TableHeader.foreground", Color.GREEN);
        UIManager.put("TableHeader.font", new Font("SansSerif", Font.BOLD, 16));

        String getDonationsQuery = "SELECT p.firstName as 'First Name', p.lastName as 'Last Name', DATE_FORMAT(d.donationDate, '%b %D, %Y') as 'Donation Date', d.donationAmount as Amount "
                + "FROM donations d "
                + "inner join donors o on d.donorId = o.donorId "
                + "inner join persons p on o.personId = p.personId "
                + "ORDER BY d.donationDate DESC "
                + "LIMIT 100";

      //Creates connection and runs query  - DB      
        conn = DBconnection.getConnection();
        PreparedStatement stmt = (PreparedStatement) conn.prepareStatement(getDonationsQuery);
        ResultSet rs = (ResultSet) stmt.executeQuery();
        ResultSetMetaData md = (ResultSetMetaData) rs.getMetaData();

      //Using a DefaultTableModel to pull column information and row data from query. - DB
        myTable donationModel = new myTable();

        int donationsColCount = md.getColumnCount();

        String[] columnNames = new String[donationsColCount];
        for (int i = 1; i <= donationsColCount; i++)
        {
            columnNames[i - 1] = md.getColumnName(i);
        }

        donationModel.setColumnIdentifiers(columnNames);

        while (rs.next())
        {
            Object[] data = new String[donationsColCount];
            for (int i = 1; i <= donationsColCount; i++)
            {
                data[i - 1] = rs.getString(i);
            }
            donationModel.addRow(data);
        }
      
        JLabel ttitleLabel = new JLabel("**100 Most Recent Donations**");
        ttitleLabel.setForeground(EPovertyMain.font);
        ttitleLabel.setFont(new Font("Serif", Font.PLAIN, font));
        gBC.fill = GridBagConstraints.HORIZONTAL;
        ttitleLabel.setBorder(bottom);
        topLabel.add(ttitleLabel, gBC);

        gBC.gridx = 0;
        gBC.gridy = 1;
        gBC.fill = GridBagConstraints.VERTICAL;
        gBC.anchor = GridBagConstraints.CENTER;

        JTable donationsTable = new JTable(donationModel);
        donationsTable.enableInputMethods(false);
        JScrollPane withdrawlScrollPane = new JScrollPane(donationsTable);
        donationsTable.setFillsViewportHeight(true);
        topDonationsTab.add(withdrawlScrollPane, gBC);
    }

    private void addIndividualDoorData() {
        JLabel titleLabel = new JLabel("**Donor Search**");
        titleLabel.setForeground(EPovertyMain.font);
        titleLabel.setFont(new Font("Serif", Font.PLAIN, font));
        gBC.gridx = 0;
        gBC.gridy = 0;
        gBC.weightx = 1;
        gBC.fill = GridBagConstraints.HORIZONTAL;
        gBC.anchor = GridBagConstraints.CENTER;
        gBC.gridwidth = GridBagConstraints.REMAINDER;
        titleLabel.setBorder(bottom);
        middleDonationsTab.add(titleLabel, gBC);
        gBC.gridwidth = 1;
        JLabel donorLabel = new JLabel("Donor: ");
        donorLabel.setForeground(EPovertyMain.font);
        donorLabel.setFont(new Font("Serif", Font.BOLD, font));
        donorLabel.setBorder(topLeftBottom);
        gBC.gridx = 0;
        gBC.gridy = 1;
        middleDonationsTab.add(donorLabel, gBC);
      
      //Donor first and last name text field
        donorName = new JLabel("(Please select person below)");
        donorName.setForeground(Color.GREEN);
        donorName.setFont(new Font("Serif", Font.BOLD, font));
        donorName.setBorder(topRightBottom);
        gBC.gridx = 1;
        gBC.gridy = 1;
        gBC.fill = GridBagConstraints.BOTH;
        middleDonationsTab.add(donorName, gBC);
      
            //Donor phone number Label
        JLabel phoneLabel = new JLabel("Phone: ");
        phoneLabel.setForeground(EPovertyMain.font);
        phoneLabel.setFont(new Font("Serif", Font.BOLD, font-4));
        gBC.gridx = 0;
        gBC.gridy = 3;
        middleDonationsTab.add(phoneLabel, gBC);
      
      //Phone number text field
        phone = new JLabel("N/A");
        phone.setForeground(Color.CYAN);
        phone.setFont(new Font("Serif", Font.PLAIN, font-4));
        gBC.gridx = 1;
        gBC.gridy = 3;
        middleDonationsTab.add(phone, gBC);
      
      //Donor email Label
        JLabel emailLabel = new JLabel("E-mail: ");
        emailLabel.setForeground(EPovertyMain.font);
        emailLabel.setFont(new Font("Serif", Font.BOLD, font-4));
        gBC.gridx = 0;
        gBC.gridy = 4;
        middleDonationsTab.add(emailLabel, gBC);
      //email text field
        email = new JLabel("N/A");
        email.setForeground(Color.CYAN);
        email.setFont(new Font("Serif", Font.PLAIN, font-4));
        gBC.gridx = 1;
        gBC.gridy = 4;
        middleDonationsTab.add(email, gBC);
      
      //Total Donations Label
        JLabel totalDonationLabel = new JLabel("Total Donations: ");
        totalDonationLabel.setForeground(EPovertyMain.font);
        totalDonationLabel.setFont(new Font("Serif", Font.BOLD, font-4));
        gBC.gridx = 3;
        gBC.gridy = 1;
        middleDonationsTab.add(totalDonationLabel, gBC);
      
      //Total Donations 
        totalDonation = new JLabel("N/A");
        totalDonation.setForeground(Color.CYAN);
        totalDonation.setFont(new Font("Serif", Font.BOLD, font-4));
        gBC.gridx = 4;
        gBC.gridy = 1;
        middleDonationsTab.add(totalDonation, gBC);
      
      
      //Last Donation Label
        JLabel lastDonationLabel = new JLabel("Last Donation Information: ");
        lastDonationLabel.setForeground(EPovertyMain.font);
        lastDonationLabel.setFont(new Font("Serif", Font.BOLD, font-4));
        lastDonationLabel.setBorder(topLeft);
        gBC.gridx = 3;
        gBC.gridy = 2;
        middleDonationsTab.add(lastDonationLabel, gBC);
        JLabel ldlFiller1 = new JLabel(" ");
        ldlFiller1.setFont(new Font("Serif", Font.BOLD, font-4));
        ldlFiller1.setBorder(left);
        gBC.gridx = 3;
        gBC.gridy = 3;
        gBC.fill = GridBagConstraints.BOTH;
        middleDonationsTab.add(ldlFiller1, gBC);
        JLabel ldlFiller2 = new JLabel(" ");
        ldlFiller2.setFont(new Font("Serif", Font.BOLD, font-4));
        ldlFiller2.setBorder(leftBottom);
        gBC.gridx = 3;
        gBC.gridy = 4;
        gBC.fill = GridBagConstraints.BOTH;
        middleDonationsTab.add(ldlFiller2, gBC);
        JLabel ldlFiller3 = new JLabel(" ");
        ldlFiller3.setFont(new Font("Serif", Font.BOLD, font-4));
        ldlFiller3.setBorder(topRight);
        gBC.gridx = 4;
        gBC.gridy = 2;
        gBC.fill = GridBagConstraints.BOTH;
        middleDonationsTab.add(ldlFiller3, gBC);
      
      
      //Last donation date and amount text field
        lastDonationDate = new JLabel("Date: " + "N/A");
        lastDonationDate.setForeground(Color.CYAN);
        lastDonationDate.setFont(new Font("Serif", Font.PLAIN, font-4));
        lastDonationDate.setBorder(right);
        gBC.gridx = 4;
        gBC.gridy = 3;
        middleDonationsTab.add(lastDonationDate, gBC);
      
        lastDonationAmount = new JLabel("Amount: " + "N/A");
        lastDonationAmount.setForeground(Color.CYAN);
        lastDonationAmount.setFont(new Font("Serif", Font.PLAIN, font-4));
        lastDonationAmount.setBorder(bottomRight);
        gBC.gridx = 4;
        gBC.gridy = 4;
        middleDonationsTab.add(lastDonationAmount, gBC);
      
      //Filler Space
        JLabel filler = new JLabel("          ");
        gBC.gridx = 2;
        gBC.fill = GridBagConstraints.VERTICAL;
        middleDonationsTab.add(filler, gBC);
    }

    private void addSearchData() throws SQLException {
        JLabel fromLabel = new JLabel("Donor First Name: ");
        fromLabel.setForeground(EPovertyMain.font);
        fromLabel.setFont(new Font("Serif", Font.PLAIN, font));
        gBC.weightx = 0.5;
        gBC.gridx = 0;
        gBC.gridy = 1;
        gBC.anchor = GridBagConstraints.EAST;
        gBC.fill = GridBagConstraints.NONE;
        gBC.ipady = 0;
        bottomDonationsTab.add(fromLabel, gBC);

        JLabel lNameLabel = new JLabel("Last Name: ");
        lNameLabel.setForeground(EPovertyMain.font);
        lNameLabel.setFont(new Font("Serif", Font.PLAIN, font));
        gBC.weightx = 0.5;
        gBC.gridx = 0;
        gBC.gridy = 2;
        gBC.anchor = GridBagConstraints.EAST;
        gBC.fill = GridBagConstraints.NONE;
        gBC.ipady = 0;
        bottomDonationsTab.add(lNameLabel, gBC);

      //Column 2 - DB
        firstName_TF = new JTextField(12);
        firstName_TF.setForeground(Color.WHITE);
        firstName_TF.setFont(new Font("Serif", Font.PLAIN, font));
        firstName_TF.setColumns(15);
        gBC.weightx = 0.25;
        gBC.gridx = 1;
        gBC.gridy = 1;
        gBC.anchor = GridBagConstraints.WEST;
        gBC.fill = GridBagConstraints.HORIZONTAL;
        bottomDonationsTab.add(firstName_TF, gBC);

        lastName_TF = new JTextField(12);
        lastName_TF.setForeground(EPovertyMain.font);
        lastName_TF.setFont(new Font("Serif", Font.PLAIN, font));
        lastName_TF.setColumns(15);
        gBC.weightx = 0.25;
        gBC.gridx = 1;
        gBC.gridy = 2;
        gBC.anchor = GridBagConstraints.WEST;
        gBC.fill = GridBagConstraints.HORIZONTAL;
        bottomDonationsTab.add(lastName_TF, gBC);

        JButton search = new JButton("Search");
        search.setForeground(EPovertyMain.font);
        search.setFont(new Font("Serif", Font.PLAIN, font));
        gBC.weightx = 0.25;
        gBC.gridx = 1;
        gBC.gridy = 3;
        gBC.anchor = GridBagConstraints.BELOW_BASELINE_LEADING;
        bottomDonationsTab.add(search, gBC);

        String query = "SELECT DISTINCT firstName as 'First Name', lastName as 'Last Name' "
                + "FROM donations d "
                + "inner join donors o on d.donorId = o.donorId "
                + "inner join persons p on o.personId = p.personId "
                + "WHERE p.firstName LIKE '%%' "
                + "AND p.lastName LIKE '%%'";
        pstmt = (PreparedStatement) conn.prepareStatement(query);
        prs = (ResultSet) pstmt.executeQuery();
        pmd = (ResultSetMetaData) prs.getMetaData();
      
        for (int i = 1; i <= pmd.getColumnCount(); i++)
        {
            pColNames[i - 1] = pmd.getColumnName(i);
        }
        pTable.setColumnIdentifiers(pColNames);

        while (prs.next())
        {
            Object[] pdata = new String[pColCount];
            for (int i = 1; i <= pColCount; i++)
            {
                pdata[i - 1] = prs.getString(i);
            }
            pTable.addRow(pdata);
        }

        gBC.weightx = .5;
        gBC.weighty = 1;
        gBC.gridheight = 10;
        gBC.gridwidth = 10;
        gBC.gridx = 3;
        gBC.gridy = 0;
        gBC.anchor = GridBagConstraints.CENTER;
        gBC.fill = GridBagConstraints.VERTICAL;

        pScrollPane.setPreferredSize(new Dimension(500, 100));

        pJTable.enableInputMethods(false);
        pJTable.setFillsViewportHeight(true);
        pJTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        bottomDonationsTab.add(pScrollPane, gBC);
        
        search.addActionListener(
                new ActionListener()
                {
            @Override
                    public void actionPerformed(ActionEvent e)
                    {
                        String firstName = firstName_TF.getText();
                        String lastName = lastName_TF.getText();
                        try
                        {
                            int done = pTable.getRowCount();
                            for (int i = 0; i < done; i++)
                            {
                                pTable.removeRow(0);
                            }

                            conn = DBconnection.getConnection();
                            String query = "SELECT DISTINCT firstName, lastName "
                                    + "FROM donations d "
                                    + "inner join donors o on d.donorId = o.donorId "
                                    + "inner join persons p on o.personId = p.personId "
                                    + "WHERE p.firstName LIKE '" + firstName + "%' "
                                    + "AND p.lastName LIKE '" + lastName + "%'";
                            pstmt = (PreparedStatement) conn.prepareStatement(query);
                            prs = (ResultSet) pstmt.executeQuery();
                            pmd = (ResultSetMetaData) prs.getMetaData();
                            
                            while (prs.next())
                            {
                                Object[] data = new String[pColCount];
                                for (int i = 1; i <= pColCount; i++)
                                {
                                    data[i - 1] = prs.getString(i);
                                }
                                pTable.addRow(data);
                            }

                            pJTable.enableInputMethods(false);
                            pJTable.setFillsViewportHeight(true);
                            pJTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                            bottomDonationsTab.add(pScrollPane, gBC);
                        }
                        catch (SQLException ex)
                        {
                            Logger.getLogger(Donations.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        catch (ClassNotFoundException ex)
                        {
                            Logger.getLogger(Donations.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                });
    }

   //Prevents cells from being edited in table by overriding isCellEditable.
   public class myTable extends DefaultTableModel
   {
      @Override
      public boolean isCellEditable(int row, int col)
      {
         return false;
      }
   }
}